import React, { useRef, useState } from 'react';
function App() {
    let timer = useRef(null);
    const [count, setCount] = useState(0);
    const start = () => {
        timer.current = setInterval(() => {
            setCount((prev) => prev + 1);
        }, 100);
    };
    const end = () => {
        clearInterval(timer.current);
    };
    // null 表示一个空对象  2： 变量==null
    //  obj   console.log(obj.a )
    return (
        <>
            <div>
                <h1>计时器场景</h1>
                <h2>{count}</h2>
                <button onClick={start}>start</button>
                <button onClick={end}>end</button>
            </div>
        </>
    );
}

export default App;
